package com.memorypalace.deck.vo;

import java.util.Date;

import com.memorypalace.util.DateUtil;

public class ScreenDate {
	/**
	 * 0:0:0 23:59:59.inpast value值为天数
	 * 
	 * @param value
	 * @param pattern
	 * @param from
	 * @param to
	 */
	public ScreenDate(Date value, String pattern, Date from, Date to) {
		super();
		this.value = value;
		this.pattern = pattern;
		this.from = from;
		this.to = to;
		// if("inpast".equals(pattern)){
		// this.from = DateUtil.getTodayEnd(DateUtil.getTodayBegin(new Date(),
		// value));
		// this.to = DateUtil.getTodayEnd(new Date());
		// }
	}

	private Date value;// day
	private Integer relativeValue; // 相对的是多少天
	private String pattern;// is not before after inpast notinpast infuture
							// notinfuture inrange

	// 如果pattern是inrange,下面两个有值
	private Date from;
	private Date to;

	public Date getValue() {
		return value;
	}

	public void setValue(Date value) {
		this.value = value;
	}

	public String getPattern() {
		return pattern;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
		if (this.value != null) {
			if ("is".equals(pattern)) {
				this.from = DateUtil.getTodayBegin(value);
				this.to = DateUtil.getTodayEnd(value);
			}
			if ("not".equals(pattern)) {
				this.from = DateUtil.getTodayBegin(value);
				this.to = DateUtil.getTodayEnd(value);
			}
			if ("before".equals(pattern)) {
				this.to = DateUtil.getTodayEnd(value);
			}
			if ("after".equals(pattern)) {
				this.from = DateUtil.getTodayBegin(value);
			}
		}
		if (this.relativeValue != null) {
			Date newDate = new Date(new Date().getTime() + relativeValue * 24 * 3600 * 1000);
			if ("is".equals(pattern)) {
				this.from = DateUtil.getTodayBegin(newDate);
				this.to = DateUtil.getTodayEnd(newDate);
			}
			if ("not".equals(pattern)) {
				this.from = DateUtil.getTodayBegin(newDate);
				this.to = DateUtil.getTodayEnd(newDate);
			}
			if ("before".equals(pattern)) {
				this.to = DateUtil.getTodayEnd(newDate);
			}
			if ("after".equals(pattern)) {
				this.from = DateUtil.getTodayBegin(newDate);
			}
		}
		if (value == null && relativeValue == null) {
			if ("before".equals(pattern)) {
				this.to = DateUtil.getTodayEnd(this.to);
			}
			if ("after".equals(pattern)) {
				this.from = DateUtil.getTodayBegin(this.from);
			}
		}
	}

	public Date getFrom() {
		return from;
	}

	public void setFrom(Date from) {
		this.from = from;
	}

	public Date getTo() {
		return to;
	}

	public void setTo(Date to) {
		this.to = to;
	}

	@Override
	public String toString() {
		return "ScreenDate [value=" + value + ", pattern=" + pattern + ", from=" + from + ", to=" + to + "]";
	}

	public Integer getRelativeValue() {
		return relativeValue;
	}

	public void setRelativeValue(Integer relativeValue) {
		this.relativeValue = relativeValue;
	}
}
